require('../../../assets/css/main.css')
import Vue from 'vue'
//import App from './errorApp'
import 'assets/js/wii_entry';
import 'assets/js/common';
import {Utils} from 'wmu2';
new Vue({
   el:'#app',
   data(){
			return{
				hasAddress:true,
				noAddress:false
			}
		},
		mounted() {
		$('body').css('display','block');
		GLOBAL.ajaxRequesting = false;
		console.log($(window).height())
	           instructionScroll();
        function instructionScroll(){
            var winH = $(window).height();
            var mainH = $('.w560').height();
            var mt = $('.w560').offset().top
            var h = winH - mainH-mt;
            $('.submit-success-bottom').css({
                height: h+'px',
                overflowY: 'scroll',
                boxSizing: 'border-box'
            })
        };
                isShowNewField();
//        是否显示新字段
        function isShowNewField() {
            var NewField = $('#J_NewField');
            NewField.hide();
            if ($CONFIG.newField.isNewField) {
                NewField.show();
            }
        }
        //  验证用户提交信息的JS
            var feel = {
            NAMEERROR: "请输入正确的姓名",
            PHONEERROR: "请输入正确的手机号",
            ADDRESSERROR: "请输入正确的地址",
            ISNEWFIELD: '请输入正确的'
        };
        $('#submitBtn').bind("touchstart", function (event) {
//        $('#submitBtn').bind("click", function (event) {
	        if(GLOBAL.ajaxRequesting){
	           return false 
	        };
            $("#J_SuccessForm").submit();
        });
        $("#J_SuccessForm").submit(function () {
            var username = $("#username").val();
            var phone = $("#phone").val();
            var phoneReg = /^1[34578]\d{9}$/;
            var address = $("#address").val();
            var newFieldVal = $('#newField').val();
           
            if (username.length <= 1 || GLOBAL.checkNull(username)) {
                GLOBAL.pop(feel.NAMEERROR);
                return false;
            }
            if (GLOBAL.checkNull(phone) || !phoneReg.test(phone)) {
                GLOBAL.pop(feel.PHONEERROR);
                return false;
            }
            if ($("#address").length > 0) {
                if (address.length <= 1 || GLOBAL.checkNull(address)) {
                    GLOBAL.pop(feel.ADDRESSERROR);
                    return false;
                }
            }
            if (!newFieldVal && $CONFIG.newField.isNewFieldVerify) {
                GLOBAL.pop(feel.ISNEWFIELD + $("#new_field_name").text());
                return false;
            }
            GLOBAL.showLoading();
            var actId = $("#act_id").val();
            var userAwardId = $("#user_award_id").val();
            GLOBAL.ajaxRequesting = true;   //只能发生一次AJAX请求
            $.ajax({
                url: $CONFIG.page.submit_url,
                type: 'post',
                dataType: 'json',
                data: {id: $CONFIG.page.act_id, user_award_id: userAwardId, user_name: username, phone: phone, address: address,new_field:newFieldVal},
                success: function (data) {
                    GLOBAL.hideLoading();
                    if (data.ret == 1) {
                        GLOBAL.pop(data.msg);
                    } else {
                        var realData = data.data;
                        //跳转到
                        window.location.href = data.data.jump_url;
                    }
                    GLOBAL.ajaxRequesting = false;
                },
                error: function () {
                    GLOBAL.hideLoading();
                    GLOBAL.pop("提交用户信息失败!");
                    GLOBAL.ajaxRequesting = false;
                }
            });
            return false;
        })


   }
})